<?php
namespace app\adminapi\logic;
class AuthLogic{
    public function check(){
        $controller = request()->controller();
        $action = request()->action();
        if($controller == 'Index' && $action == "index"){
            return true;
        }
        $user_id = input('user_id');
        $info = \app\common\model\Admin::find($user_id);
        $role_id = $info['role_id'];
        if($role_id==1){
            return true;
        }
        $role = \app\common\model\Role::find($role_id);
        $role_auth_ids = $role['role_auth_ids'];
        $role_auth_ids = explode(',',$role_auth_ids);
        $auth =\app\common\model\Auth::where('auth_c',$controller)->where('auth_a',$action)->find();
        if(empty($auth)){
            return false;
        }
        if(in_array($auth['id'],$role_auth_ids)){
            return true;
        }else{
            return false;
        }
    }
}